//
//  YDChoosePayTypeCell.m
//  PeiZiWangBei
//
//  Created by 巨彦新 on 2017/12/19.
//  Copyright © 2017年 LK-IOS. All rights reserved.
//

#import "YDChoosePayTypeCell.h"
#import "YDRechargeBankListModel.h"
#import "UIImageView+WebCache.h"

@interface YDChoosePayTypeCell()

@property (nonatomic, strong)UILabel *payTitle;
@property (nonatomic, strong)UIImageView *payIcon;
@property (nonatomic, strong)UILabel *line;

@end

@implementation YDChoosePayTypeCell


-(void)setModel:(YDRechargeBankListModel *)model
{
    _model = model;
    [self.payIcon mas_updateConstraints:^(MASConstraintMaker *make) {
        make.width.height.equalTo(@26);
    }];
    
    [self.payIcon sd_setImageWithURL:[NSURL URLWithString:model.iconLink] placeholderImage:[UIImage imageNamed:@"zhanweibank"]];
   
    self.payTitle.text = model.bankName;
    
    if (model.isSelected) {
        self.selectedIcon.hidden = NO;
    }else{
        self.selectedIcon.hidden = YES;
    }
    
    
}


+ (instancetype)cellWithTableView:(UITableView *)tableView
{
    static NSString *rechargeTableCell = @"YDChoosePayTypeCell";
    YDChoosePayTypeCell *cell = [tableView dequeueReusableCellWithIdentifier:rechargeTableCell];
    if (cell == nil) {
        cell = [[YDChoosePayTypeCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:rechargeTableCell];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    return cell;
}

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        self.contentView.backgroundColor = NumberColor(255, 255, 255);
        self.backgroundColor = NumberColor(255, 255, 255);
        [self payIcon];
        [self payTitle];
        [self selectedIcon];
        [self line];

    }
    return self;
}



-(void)setPayDic:(NSDictionary *)payDic
{
    _payDic = payDic;
    NSString *title = [payDic objectForKey:@"title"];
    if ([title isEqualToString:@"支付宝"]) {
        self.payTitle.text = @"支付宝充值";
        self.payIcon.image = [UIImage imageNamed:@"zhifubao"];
    }
    else if ([title isEqualToString:@"银行卡"])
    {
        self.payTitle.text = @"银联充值";
        self.payIcon.image = [UIImage imageNamed:@"yinlian"];
    }
    else if ([title isEqualToString:@"京东"])
    {
        self.payTitle.text = @"京东充值";
        self.payIcon.image = [UIImage imageNamed:@"jingdongpay"];
    }
    else
    {
        self.payTitle.text = @"QQ充值";
        self.payIcon.image = [UIImage imageNamed:@"qqpay"];
    }

    
//    NSNumber *isSelected = [payDic objectForKey:@"isSelected"];
//
//    self.selectedIcon.hidden = ![isSelected boolValue];
    
}
- (UIImageView *)payIcon
{
    if (!_payIcon) {
        _payIcon = [UIImageView new];
        [self.contentView addSubview:_payIcon];
        _payIcon.contentMode = UIViewContentModeScaleAspectFill;
        [_payIcon mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(@(rate375(20)));
            make.centerY.equalTo(self.contentView);
        }];
        
    }
    return _payIcon;
}

- (UILabel *)payTitle
{
    if (!_payTitle) {
        _payTitle = [UILabel new];
        [self.contentView addSubview:_payTitle];
        _payTitle.font = [UIFont systemFontOfSize:14];
        [_payTitle mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(_payIcon.mas_right).offset(rate375(6));
            make.centerY.equalTo(_payIcon);
            
        }];
        _payTitle.textColor = [UIColor colorWithHexString:battleshipGrey];
    }
    return _payTitle;
}

- (UIImageView *)selectedIcon
{
    if (!_selectedIcon) {
        _selectedIcon = [UIImageView new];
        [self.contentView addSubview:_selectedIcon];
        [_selectedIcon mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(@(-rate375(18)));
            make.centerY.equalTo(_payTitle);
        }];
        _selectedIcon.image = [UIImage imageNamed:@"xialakuang-xuanzhong"];
        _selectedIcon.hidden = YES;
    }
    return _selectedIcon;
}
-(UILabel *)line
{
    if (!_line) {
        _line = [UILabel new];
        [self.contentView addSubview:_line];

        [_line mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.bottom.equalTo(self.contentView);
            make.height.equalTo(@1);
        }];
        _line.backgroundColor = [UIColor colorWithHexString:mainGray];
    }
    return _line;
}
@end
